package com.tanhua.server.controller;

import com.tanhua.domain.vo.CountsVo;
import com.tanhua.domain.vo.FriendVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.UserInfoVo;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("users")
public class UserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户信息
     *
     * @param userID
     * @param huanxinID
     * @return
     */
    @GetMapping
    public ResponseEntity getUserInfo(Long userID, Long huanxinID) {
        UserInfoVo vo = userService.getUserInfo(userID, huanxinID);
        return ResponseEntity.ok(vo);
    }

    /**
     * 更新登录用户信息
     *
     * @param vo
     * @return
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestBody UserInfoVo vo) {
        userService.updateUserInfo(vo);
        return ResponseEntity.ok(null);
    }

    /**
     * 互相喜欢、喜欢、粉丝统计
     *
     * @return
     */
    @GetMapping("counts")
    public ResponseEntity counts() {
        CountsVo vo = userService.counts();
        return ResponseEntity.ok(vo);
    }

    /**
     * 互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表
     *
     * @param type 1 互相关注
     *             2 我关注
     *             3 粉丝
     *             4 谁看过我
     * @return
     */
    @GetMapping("friends/{type}")
    public ResponseEntity queryUserLikeList(@PathVariable int type,
                                            @RequestParam(value = "page", defaultValue = "1") Long page,
                                            @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize,
                                            @RequestParam(value = "nickname",required=false) String nickname) {
        PageResult<FriendVo> pageResult = userService.queryUserLikeList(type,page,pageSize,nickname);
        return ResponseEntity.ok(pageResult);
    }
}
